﻿using System;
using System.Collections.Generic;
using System.Linq;
using WCFHostingModel;

namespace WCFHostingServiceLibrary
{
    public class ArticleService : IArticleService
    {
        public IEnumerable<ArticleModel> GetArticleModels(string uid, int page, int size)
        {
            if (string.IsNullOrWhiteSpace(uid)) throw new ArgumentNullException(nameof(uid));
            var data = TestData.Articles;
            return data?.Where(x => x.Author == uid).Skip((page - 1)*size).Take(size);
        }

        public ArticleModel GetArticleModel(string aid)
        {
            if (string.IsNullOrWhiteSpace(aid)) throw new ArgumentNullException(nameof(aid));
            var data = TestData.Articles;
            return data?.FirstOrDefault(x => x.Aid == aid);
        }
    }
}